<?php
namespace Modules\Order\Database\Seeders;

use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;

/**
 * 生成后台订单管理菜单
 * @author RenJianHong
 * @date 2021-08-3 10:46
 */
class OrderAuthMenuSeeder extends Seeder
{
    public function run()
    {
        if (Schema::hasTable('auth_menu')){
            $arr = $this->defaultInfo();
            if(!empty($arr) && is_array($arr)) {
                // 删除原来已存在的菜单
                $module = "order";
                if($module != ""){
                    DB::table('auth_menu')->where("module", $module)->delete();
                }

                $this->addInfo($arr);
            }
        }
    }

    /**
     * 遍历新增菜单
     * @param array $data
     * @param int $pid
     */
    private function addInfo(array $data, $pid = 0)
    {
        $module = "order";
        foreach ($data as $item) {
            $newPid = DB::table('auth_menu')->insertGetId([
                'pid' => $item['pid'] ?? $pid,
                'href' => $item['href'],
                'title' => $item['title'],
                'icon' => $item['icon'],
                'type' => $item['type'],
                'status' => $item['status'],
                'remark' => $item['remark'],
                'target' => $item['target'],
                'sort' => $item['sort'] ?? 99,
                'createtime' => $item['createtime'],
                'module' => $item["module"],
                'menus' => $item["menus"],
            ]);
            if($newPid <= 0) break;
            if(isset($item["contents"]) && is_array($item["contents"]) && !empty($item["contents"])) $this->addInfo($item["contents"], $newPid);
        }
    }

    /**
     * 设置后台管理菜单路由信息
     * @pid 父级
     * @href 路由
     * @title 菜单标题
     * @icon 图标
     * @type int 类型 0 顶级目录 1 目录 2 菜单 3 按钮
     * @status 状态 1 正常 2 停用
     * @remark 备注
     * @target 跳转方式
     * @createtime 创建时间
     */
    private function defaultInfo()
    {
        $module = "order";
        $time = time();
        return [
            [
                "pid" => 10004,
                "href" => "",
                "title" => "订单管理",
                "icon" => 'fa fa-align-justify',
                "type" => 1,
                "status" => 1,
                "remark" => "订单管理",
                "target" => "_self",
                "sort" => 14,
                "createtime" => $time,
                'module' => $module,
                "menus" => $module == "" ? $module : $module . "-1",
                "contents" => [
                    [   //  订单列表
                        "href" => "/admin/order/list",
                        "title" => "订单列表",
                        "icon" => 'fa fa-align-justify',
                        "type" => 2,
                        "status" => 1,
                        "remark" => "订单列表",
                        "target" => "_self",
                        "sort" => 10,
                        "createtime" => $time,
                        'module' => $module,
                        "menus" => $module == "" ? $module : $module . "-2",
                        "contents" => [
                            [
                                "href" => "/admin/order/list",
                                "title" => "查看订单列表",
                                "icon" => 'fa fa-window-maximize',
                                "type" => 3,
                                "status" => 1,
                                "remark" => "查看订单列表",
                                "target" => "_self",
                                "sort" => 10,
                                "createtime" => $time,
                                'module' => $module,
                                "menus" => $module == "" ? $module : $module . "-3",
                            ],
                            [
                                "href" => "/admin/order/ajaxList",
                                "title" => "获取订单列表数据",
                                "icon" => 'fa fa-window-maximize',
                                "type" => 3,
                                "status" => 1,
                                "remark" => "获取订单列表数据",
                                "target" => "_self",
                                "sort" => 10,
                                "createtime" => $time,
                                'module' => $module,
                                "menus" => $module == "" ? $module : $module . "-4",
                            ],
                            [
                                "href" => "/admin/order/cancel",
                                "title" => "取消订单",
                                "icon" => 'fa fa-window-maximize',
                                "type" => 3,
                                "status" => 1,
                                "remark" => "取消订单",
                                "target" => "_self",
                                "sort" => 10,
                                "createtime" => $time,
                                'module' => $module,
                                "menus" => $module == "" ? $module : $module . "-5",
                            ],
                            [
                                "href" => "/admin/order/detail",
                                "title" => "查看订单详情",
                                "icon" => 'fa fa-window-maximize',
                                "type" => 3,
                                "status" => 1,
                                "remark" => "查看订单详情",
                                "target" => "_self",
                                "sort" => 10,
                                "createtime" => $time,
                                'module' => $module,
                                "menus" => $module == "" ? $module : $module . "-6",
                            ],
                            [
                                "href" => "/admin/order/send",
                                "title" => "订单发货",
                                "icon" => 'fa fa-window-maximize',
                                "type" => 3,
                                "status" => 1,
                                "remark" => "订单发货",
                                "target" => "_self",
                                "sort" => 10,
                                "createtime" => $time,
                                'module' => $module,
                                "menus" => $module == "" ? $module : $module . "-7",
                            ],
                            [
                                "href" => "/admin/order/recycle",
                                "title" => "移入回收站",
                                "icon" => 'fa fa-window-maximize',
                                "type" => 3,
                                "status" => 1,
                                "remark" => "移入回收站",
                                "target" => "_self",
                                "sort" => 10,
                                "createtime" => $time,
                                'module' => $module,
                                "menus" => $module == "" ? $module : $module . "-8",
                            ],
                            [
                                "href" => "/admin/order/delete",
                                "title" => "删除订单",
                                "icon" => 'fa fa-window-maximize',
                                "type" => 3,
                                "status" => 1,
                                "remark" => "删除订单",
                                "target" => "_self",
                                "sort" => 10,
                                "createtime" => $time,
                                'module' => $module,
                                "menus" => $module == "" ? $module : $module . "-9",
                            ],
                            [
                                "href" => "/admin/order/batchDelete",
                                "title" => "清空回收站",
                                "icon" => 'fa fa-window-maximize',
                                "type" => 3,
                                "status" => 1,
                                "remark" => "清空回收站",
                                "target" => "_self",
                                "sort" => 10,
                                "createtime" => $time,
                                'module' => $module,
                                "menus" => $module == "" ? $module : $module . "-10",
                            ],
                            [
                                "href" => "/admin/order/refund",
                                "title" => "取消订单审核",
                                "icon" => 'fa fa-window-maximize',
                                "type" => 3,
                                "status" => 1,
                                "remark" => "取消订单审核",
                                "target" => "_self",
                                "sort" => 10,
                                "createtime" => $time,
                                'module' => $module,
                                "menus" => $module == "" ? $module : $module . "-10",
                            ],
                        ],
                    ],
                    [   //  订单消息提醒
                        "href" => "/admin/order_message/list",
                        "title" => "消息提醒",
                        "icon" => 'fa fa-bell',
                        "type" => 2,
                        "status" => 1,
                        "remark" => "消息提醒",
                        "target" => "_self",
                        "sort" => 7,
                        "createtime" => $time,
                        'module' => $module,
                        "menus" => $module == "" ? $module : $module . "-11",
                        "contents" => [
                            [
                                "href" => "/admin/order_message/list",
                                "title" => "查看消息提醒列表",
                                "icon" => 'fa fa-window-maximize',
                                "type" => 3,
                                "status" => 1,
                                "remark" => "查看消息提醒列表",
                                "target" => "_self",
                                "sort" => 10,
                                "createtime" => $time,
                                'module' => $module,
                                "menus" => $module == "" ? $module : $module . "-12",
                            ],
                            [
                                "href" => "/admin/order_message/ajaxList",
                                "title" => "获取消息提醒列表数据",
                                "icon" => 'fa fa-window-maximize',
                                "type" => 3,
                                "status" => 1,
                                "remark" => "获取消息提醒列表数据",
                                "target" => "_self",
                                "sort" => 10,
                                "createtime" => $time,
                                'module' => $module,
                                "menus" => $module == "" ? $module : $module . "-13",
                            ],
                            [
                                "href" => "/admin/order_message/batchDelete",
                                "title" => "批量删除消息提醒",
                                "icon" => 'fa fa-window-maximize',
                                "type" => 3,
                                "status" => 1,
                                "remark" => "批量删除消息提醒",
                                "target" => "_self",
                                "sort" => 10,
                                "createtime" => $time,
                                'module' => $module,
                                "menus" => $module == "" ? $module : $module . "-14",
                            ],
                            [
                                "href" => "/admin/order_message/soundAll",
                                "title" => "批量标记为已提醒",
                                "icon" => 'fa fa-window-maximize',
                                "type" => 3,
                                "status" => 1,
                                "remark" => "批量标记为已提醒",
                                "target" => "_self",
                                "sort" => 10,
                                "createtime" => $time,
                                'module' => $module,
                                "menus" => $module == "" ? $module : $module . "-15",
                            ],
                            [
                                "href" => "/admin/order_message/delete",
                                "title" => "删除订单",
                                "icon" => 'fa fa-window-maximize',
                                "type" => 3,
                                "status" => 1,
                                "remark" => "删除订单",
                                "target" => "_self",
                                "sort" => 10,
                                "createtime" => $time,
                                'module' => $module,
                                "menus" => $module == "" ? $module : $module . "-16",
                            ],
                        ],
                    ],
                    [   //  订单批量发货
                        "href" => "/admin/order/batchSend",
                        "title" => "批量发货",
                        "icon" => 'fa fa-yelp',
                        "type" => 2,
                        "status" => 1,
                        "remark" => "批量发货",
                        "target" => "_self",
                        "sort" => 8,
                        "createtime" => $time,
                        'module' => $module,
                        "menus" => $module == "" ? $module : $module . "-17",
                        "contents" => [
                            [
                                "href" => "/admin/order/batchSend",
                                "title" => "编辑批量发货",
                                "icon" => 'fa fa-window-maximize',
                                "type" => 3,
                                "status" => 1,
                                "remark" => "编辑批量发货",
                                "target" => "_self",
                                "sort" => 10,
                                "createtime" => $time,
                                'module' => $module,
                                "menus" => $module == "" ? $module : $module . "-18",
                            ],
                        ],
                    ],
                    [   //  订单评价
                        "href" => "/admin/order_comment/list",
                        "title" => "订单评价",
                        "icon" => 'fa fa-star',
                        "type" => 2,
                        "status" => 1,
                        "remark" => "订单评价",
                        "target" => "_self",
                        "sort" => 6,
                        "createtime" => $time,
                        'module' => $module,
                        "menus" => $module == "" ? $module : $module . "-19",
                        "contents" => [
                            [
                                "href" => "/admin/order_comment/list",
                                "title" => "查看订单评价列表",
                                "icon" => 'fa fa-window-maximize',
                                "type" => 3,
                                "status" => 1,
                                "remark" => "查看订单评价列表",
                                "target" => "_self",
                                "sort" => 10,
                                "createtime" => $time,
                                'module' => $module,
                                "menus" => $module == "" ? $module : $module . "-20",
                            ],
                            [
                                "href" => "/admin/order_comment/ajaxList",
                                "title" => "获取订单评价列表数据",
                                "icon" => 'fa fa-window-maximize',
                                "type" => 3,
                                "status" => 1,
                                "remark" => "获取订单评价列表数据",
                                "target" => "_self",
                                "sort" => 10,
                                "createtime" => $time,
                                'module' => $module,
                                "menus" => $module == "" ? $module : $module . "-21",
                            ],
                            [
                                "href" => "/admin/order_comment/batchDelete",
                                "title" => "批量删除订单评价",
                                "icon" => 'fa fa-window-maximize',
                                "type" => 3,
                                "status" => 1,
                                "remark" => "批量删除订单评价",
                                "target" => "_self",
                                "sort" => 10,
                                "createtime" => $time,
                                'module' => $module,
                                "menus" => $module == "" ? $module : $module . "-22",
                            ],
                            [
                                "href" => "/admin/order_comment/delete",
                                "title" => "删除订单评价",
                                "icon" => 'fa fa-window-maximize',
                                "type" => 3,
                                "status" => 1,
                                "remark" => "删除订单评价",
                                "target" => "_self",
                                "sort" => 10,
                                "createtime" => $time,
                                'module' => $module,
                                "menus" => $module == "" ? $module : $module . "-23",
                            ],
                            [
                                "href" => "/admin/order_comment/reply",
                                "title" => "回复评价",
                                "icon" => 'fa fa-window-maximize',
                                "type" => 3,
                                "status" => 1,
                                "remark" => "回复评价",
                                "target" => "_self",
                                "sort" => 10,
                                "createtime" => $time,
                                'module' => $module,
                                "menus" => $module == "" ? $module : $module . "-24",
                            ],
                            [
                                "href" => "/admin/order_comment/add",
                                "title" => "添加虚拟评价",
                                "icon" => 'fa fa-window-maximize',
                                "type" => 3,
                                "status" => 1,
                                "remark" => "添加虚拟评价",
                                "target" => "_self",
                                "sort" => 10,
                                "createtime" => $time,
                                'module' => $module,
                                "menus" => $module == "" ? $module : $module . "-25",
                            ],
                            [
                                "href" => "/admin/order_comment/is_hide",
                                "title" => "是否隐藏状态操作",
                                "icon" => 'fa fa-window-maximize',
                                "type" => 3,
                                "status" => 1,
                                "remark" => "是否隐藏状态操作",
                                "target" => "_self",
                                "sort" => 10,
                                "createtime" => $time,
                                'module' => $module,
                                "menus" => $module == "" ? $module : $module . "-26",
                            ],
                        ],
                    ],
                    [   //  售后订单
                        "href" => "/admin/order_refund/list",
                        "title" => "售后订单",
                        "icon" => 'fa fa-list-alt',
                        "type" => 2,
                        "status" => 1,
                        "remark" => "售后订单",
                        "target" => "_self",
                        "sort" => 9,
                        "createtime" => $time,
                        'module' => $module,
                        "menus" => $module == "" ? $module : $module . "-27",
                        "contents" => [
                            [
                                "href" => "/admin/order_refund/list",
                                "title" => "查看售后订单列表",
                                "icon" => 'fa fa-window-maximize',
                                "type" => 3,
                                "status" => 1,
                                "remark" => "查看售后订单列表",
                                "target" => "_self",
                                "sort" => 10,
                                "createtime" => $time,
                                'module' => $module,
                                "menus" => $module == "" ? $module : $module . "-28",
                            ],
                            [
                                "href" => "/admin/order_refund/ajaxList",
                                "title" => "获取售后订单列表数据",
                                "icon" => 'fa fa-window-maximize',
                                "type" => 3,
                                "status" => 1,
                                "remark" => "获取售后订单列表数据",
                                "target" => "_self",
                                "sort" => 10,
                                "createtime" => $time,
                                'module' => $module,
                                "menus" => $module == "" ? $module : $module . "-29",
                            ],
                            [
                                "href" => "/admin/order_refund/refundHandle",
                                "title" => "同意申请",
                                "icon" => 'fa fa-window-maximize',
                                "type" => 3,
                                "status" => 1,
                                "remark" => "同意申请",
                                "target" => "_self",
                                "sort" => 10,
                                "createtime" => $time,
                                'module' => $module,
                                "menus" => $module == "" ? $module : $module . "-30",
                            ],
                            [
                                "href" => "/admin/order_refund/confirm",
                                "title" => "确认收货",
                                "icon" => 'fa fa-window-maximize',
                                "type" => 3,
                                "status" => 1,
                                "remark" => "确认收货",
                                "target" => "_self",
                                "sort" => 10,
                                "createtime" => $time,
                                'module' => $module,
                                "menus" => $module == "" ? $module : $module . "-31",
                            ],
                            [
                                "href" => "/admin/order_refund/delete",
                                "title" => "删除售后订单",
                                "icon" => 'fa fa-window-maximize',
                                "type" => 3,
                                "status" => 1,
                                "remark" => "删除售后订单",
                                "target" => "_self",
                                "sort" => 10,
                                "createtime" => $time,
                                'module' => $module,
                                "menus" => $module == "" ? $module : $module . "-32",
                            ],
                            [
                                "href" => "/admin/order_refund/detail",
                                "title" => "订单详情",
                                "icon" => 'fa fa-window-maximize',
                                "type" => 3,
                                "status" => 1,
                                "remark" => "订单详情",
                                "target" => "_self",
                                "sort" => 10,
                                "createtime" => $time,
                                'module' => $module,
                                "menus" => $module == "" ? $module : $module . "-31",
                            ],
                        ],
                    ],
                ],
            ],
        ];
    }
}